Hi,
I have a small problem while making a program in c#. The problem is that I would like to access record of selected columns of data table in c#. Like suppose I have a data table which have four columns namely empId, empName, empAge and empCity . Now I would like to select record of only two columns of this data table. This is prity simple in sql query but how can I perform it into data table.
Help me!
Thanks.
Anonymous User
23-Jul-2011Hi James,
You can easily select records of selected columns in DataTable. Check the code below.
DataTable dtSelectedColumns = dtOriginal.DefaultView.ToTable(false, "Column1", "Column2");
If you want those columns with distinct records then pass first parameter true except false. You can also provide as many column as you want in the parameter.
Anonymous User
23-Jul-2011Hi james,
You can get information of selected columns in following way,
//Here table represent name of that DataTable which have all columns.
Thanks.
Please mark it as answer if your problem had been resolved.